package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.EmployeeTraining;
import com.ruoyi.business.service.IEmployeeTrainingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 员工培训记录Controller
 *
 * @author ruoyi
 * @date 2024-11-18
 */
@Api(tags = "员工培训记录管理",value = "员工培训记录管理", description = "员工培训记录管理，包括查询、新增、修改、删除等功能")
@RestController
@RequestMapping("/business/training")
public class EmployeeTrainingController extends BaseController
{
    @Autowired
    private IEmployeeTrainingService employeeTrainingService;

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    @ApiOperation(value = "导入数据", notes = "导入员工培训记录数据")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<EmployeeTraining> util = new ExcelUtil<EmployeeTraining>(EmployeeTraining.class);
        List<EmployeeTraining> userList = util.importExcel("员工培训记录数据",file.getInputStream(),1);
        String operName = getUsername();
        String message = employeeTrainingService.importData(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    @ApiOperation(value = "导出模板", notes = "导出员工培训记录数据模板")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<EmployeeTraining> util = new ExcelUtil<EmployeeTraining>(EmployeeTraining.class);
        util.importTemplateExcel(response, "员工培训记录数据", "员工培训记录数据");
    }

    /**
     * 查询员工培训记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:training:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询列表", notes = "查询员工培训记录列表")
    public TableDataInfo list(EmployeeTraining employeeTraining)
    {
        startPage();
        List<EmployeeTraining> list = employeeTrainingService.selectEmployeeTrainingList(employeeTraining);
        return getDataTable(list);
    }

    /**
     * 导出员工培训记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:training:export')")
    @Log(title = "员工培训记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出数据", notes = "导出员工培训记录数据")
    public void export(HttpServletResponse response, EmployeeTraining employeeTraining)
    {
        List<EmployeeTraining> list = employeeTrainingService.selectEmployeeTrainingList(employeeTraining);
        ExcelUtil<EmployeeTraining> util = new ExcelUtil<EmployeeTraining>(EmployeeTraining.class);
        util.exportExcel(response, list, "员工培训记录数据");
    }

    /**
     * 获取员工培训记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:training:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取详情", notes = "获取员工培训记录详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(employeeTrainingService.selectEmployeeTrainingById(id));
    }

    /**
     * 新增员工培训记录
     */
    @PreAuthorize("@ss.hasPermi('system:training:add')")
    @Log(title = "员工培训记录", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增数据", notes = "新增员工培训记录")
    public AjaxResult add(@RequestBody EmployeeTraining employeeTraining)
    {
        return toAjax(employeeTrainingService.insertEmployeeTraining(employeeTraining));
    }

    /**
     * 修改员工培训记录
     */
    @PreAuthorize("@ss.hasPermi('system:training:edit')")
    @Log(title = "员工培训记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改数据", notes = "修改员工培训记录")
    public AjaxResult edit(@RequestBody EmployeeTraining employeeTraining)
    {
        return toAjax(employeeTrainingService.updateEmployeeTraining(employeeTraining));
    }

    /**
     * 删除员工培训记录
     */
    @PreAuthorize("@ss.hasPermi('system:training:remove')")
    @Log(title = "员工培训记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除数据", notes = "删除员工培训记录")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(employeeTrainingService.deleteEmployeeTrainingByIds(ids));
    }
}
